package com.huihong.internship.system.Controller;


import com.github.pagehelper.Page;
import com.huihong.internship.system.DTO.*;
import com.huihong.internship.system.Service.ApplicationService;
import com.huihong.internship.system.Service.StudentService;
import com.huihong.internship.system.VO.EnterPriseVO;
import com.huihong.internship.system.entity.InternshipScore;
import com.huihong.internship.system.entity.SysStudent;
import com.huihong.internship.system.result.PageResult;
import com.huihong.internship.system.result.Result;
import com.huihong.internship.system.annotation.JwtAuth;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
@Slf4j
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private ApplicationService applicationService;


    /**
     *查询学生信息
     * @return
     */
    @GetMapping("/info")
    @JwtAuth
    public Result<SysStudent> getStuInfo(Long userId){
        SysStudent student = studentService.getInfo(userId);
        return Result.success(student);
    }


    /**
     * 修改学生信息
     * @param sysStudent
     * @return
     */
    @PutMapping
    public Result updateStu(@RequestBody SysStudent sysStudent){
        studentService.updateStu(sysStudent);
        return  Result.success();
    }


    /**
     * 岗位分页查询
     * @param positionPageQueryDTO
     * @return
     */
    @GetMapping("/positions")
    public Result<PageResult> positionPageQuery(PositionPageQueryDTO positionPageQueryDTO){
        log.info("positionPageQueryDTO:{}",positionPageQueryDTO);
        PageResult pageResult = studentService.pageQuery(positionPageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 根据ID查询企业
     * @param enterpriseId
     * @return
     */
    @GetMapping("/enterprise/{enterpriseId}")
    public Result getEnterpriseById(@PathVariable Long enterpriseId){
        log.info("根据ID查询企业，id:{}",enterpriseId);
        EnterPriseVO enterPriseVO = studentService.getEnterPriseById(enterpriseId);
        return Result.success(enterPriseVO);
    }

    /**
     * 提交实习申请
     */
    @PostMapping("/application")
    @JwtAuth
    public Result submitApplication(@RequestBody ApplicationSubmitDTO dto, Long userId){
        Long applicationId = applicationService.submit(userId, dto);
        if (applicationId == -1L) {
            return Result.error("您已申请过该岗位，请勿重复申请");
        }
        return Result.success(new java.util.HashMap<String, Object>(){{ put("applicationId", applicationId); }});
    }

    /**
     * 查看申请状态列表
     */
    @GetMapping("/applications")
    @JwtAuth
    public Result<PageResult> getApplications(ApplicationPageQueryDTO dto, Long userId){
        PageResult pageResult = applicationService.pageQuery(userId, dto);
        return Result.success(pageResult);
    }


    /**
     * 提交实习材料
     * @param dto
     * @return
     */
    @PostMapping("/material")
    @JwtAuth
    public Result submitMaterial(@RequestBody InternshipMaterialDTO dto, Long userId){
        Long materialId = studentService.submitMaterial(userId, dto);
        return Result.success(new java.util.HashMap<String, Object>(){{ put("materialId", materialId); }});
    }


    /**
     * 分页查询材料申请
     * @param dto
     * @return
     */
    @GetMapping("/materials")
    @JwtAuth
    public Result<PageResult> getMaterials(InternshipMaterialPageQueryDTO dto, Long userId){
        PageResult pageResult = studentService.materialsPageQuery(userId, dto);
        return Result.success(pageResult);
    }

    /**
     * 查看成绩与反馈
     * @return
     */
    @GetMapping("/score")
    @JwtAuth
    public Result<InternshipScore> getEvaluation(Long userId){
        InternshipScore evaluation = studentService.getEvaluation(userId);
        return Result.success(evaluation);
    }


























}
